package  com.syqc.sensor

import androidx.recyclerview.widget.LinearLayoutManager
import com.syqc.comlib.base.BaseBarActivity
import com.syqc.comlib.databinding.IncludeRecyclerMathBinding
import com.syqc.comlib.utils.ToolbarHelper
import com.syqc.entity.ListInfo
import com.syqc.monitor.R
import com.syqc.monitor.databinding.ActivitySensorDetailBinding
import com.syqc.monitor.databinding.LayoutAddLeakBinding
import com.syqc.utils.DataUtil
import com.syqc.utils.Keys

class AddLeakActivity :
    BaseBarActivity<ActivitySensorDetailBinding>(ActivitySensorDetailBinding::inflate) {
    //明细类型  0 ：加油明细 1：漏油明细 2：加水明细  3：装载明细 4：卸载明细
    private var type: Int = 0

    override fun initView() {
        val title = intent.getStringExtra(Keys.INTENT_TITLE) ?: ""
        type = intent.getIntExtra(Keys.INTENT_TYPE, 0)
        val titleLayout = LayoutAddLeakBinding.bind(binding.root)

        val data = DataUtil.addLeak
        val desc: String
        when (type) {
            0 -> {
                desc = getString(R.string.title_oil_detail_add)
                titleLayout.tvAddLeakTotal.setText(R.string.desc_oil_add_total)
            }
            1 -> {
                desc = getString(R.string.title_oil_detail_leak)
            }
            2 -> {
                desc = getString(R.string.title_add_detail_water)
                titleLayout.tvStartTotal.setText(R.string.desc_water_before)
                titleLayout.tvEndTotal.setText(R.string.desc_water_next)
                titleLayout.tvAddLeakTotal.setText(R.string.desc_water_total)
            }
            3 -> {
                desc = getString(R.string.title_weight_detail_up)
                titleLayout.tvStartTotal.setText(R.string.desc_weight_before)
                titleLayout.tvEndTotal.setText(R.string.desc_weight_next)
                titleLayout.tvAddLeakTotal.setText(R.string.desc_weight_total)
            }
            4 -> {
                desc = getString(R.string.title_weight_detail_down)
                titleLayout.tvStartTotal.setText(R.string.desc_weight_down_before)
                titleLayout.tvEndTotal.setText(R.string.desc_weight_down_next)
                titleLayout.tvAddLeakTotal.setText(R.string.desc_weight_down_total)
            }

            5 -> {
                desc = getString(R.string.title_temp_detail_up)
                titleLayout.tvStartTotal.setText(R.string.title_temp_up_p)
                titleLayout.tvEndTotal.setText(R.string.title_temp_up_n)
                titleLayout.tvAddLeakTotal.setText(R.string.title_temp_up_num)
            }
            6 -> {
                desc = getString(R.string.title_temp_detail_down)
                titleLayout.tvStartTotal.setText(R.string.title_temp_down_p)
                titleLayout.tvEndTotal.setText(R.string.title_temp_down_n)
                titleLayout.tvAddLeakTotal.setText(R.string.title_temp_down_num)
            }
            else -> {
                desc = ""
            }
        }

        val info = if (data.isNullOrEmpty()) {
            "$title $desc "
        } else {
            "$title $desc (${DataUtil.stats?.day})"
        }

        ToolbarHelper.setToolbar(this, info)

        initRecyclerView(data)
    }

    fun initRecyclerView(data: ArrayList<ListInfo>?) {
        val unit = intent.getStringExtra(Keys.INTENT_OTHER) ?: ""
        val mRecycler = IncludeRecyclerMathBinding.bind(binding.root).recyclerView
        mRecycler.layoutManager = LinearLayoutManager(this)
        val mAdapter = AddLeakAdapter(unit)
        mRecycler.adapter = mAdapter
        mAdapter.setList(data)
    }


    override fun setListener() {

    }
}